﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AccompanyCabinet.Interface;

namespace AccompanyCabinet.Provider
{
    public enum MessageType
    {
        Information=0,
        Error = 1,
        Warning = 2
    }
    public abstract class MessageProviderBase:IMessageProvider
    {
        public abstract void Show(string content, string caption = "系统提示", MessageType messageType = Provider.MessageType.Error);
    }

    public class CustomeMessageProvider : MessageProviderBase
    {
        public CustomeMessageProvider(Form parentForm)
        {
            this.ParentWindows = parentForm;
        }
        public Form ParentWindows { get; set; }
        public override void Show(string content, string caption = "系统提示", MessageType messageType = Provider.MessageType.Error)
        {
            MessageBoxIcon defaultIcon = MessageBoxIcon.Information;
            string messageTypeStr = Enum.GetName(typeof(MessageType), messageType);
            Enum.TryParse<MessageBoxIcon>(messageTypeStr, out defaultIcon);
            ParentWindows?.Invoke(new Action(() =>
            {
                MessageBox.Show(ParentWindows, content, caption, MessageBoxButtons.OK, defaultIcon);
            }));
            
        }
    }
}
